/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ToernooiAanmaken.java
 *
 * Created on 21-dec-2011, 19:41:10
 */
package view;

import javax.swing.JOptionPane;
import model.Toernooi;

/**
 *
 * @author Nick
 */
public class ToernooiAanmaken extends javax.swing.JFrame {

    /** Creates new form ToernooiAanmaken */
    public ToernooiAanmaken() {
        initComponents();

        //Urenbox invullen
        for (int i = 0; i < 24; i++) {
            if (i < 10) {
                uurBox.addItem("0" + i);
            } else {
                uurBox.addItem("" + i);
            }
        }

        //Minutenbox invullen
        for (int i = 0; i < 60; i++) {
            if (i < 10) {
                minuutBox.addItem("0" + i);
            } else {
                minuutBox.addItem("" + i);
            }
        }



        //Dagenbox
        for (int i = 1; i <= 31; i++) {
            if (i < 10) {
                dagBox.addItem("0" + i);
            } else {
                dagBox.addItem("" + i);
            }
        }

        //Maandenbox
        for (int i = 1; i <= 12; i++) {
            if (i < 10) {
                maandBox.addItem("0" + i);
            } else {
                maandBox.addItem("" + i);
            }
        }

        //jarenbox
        for (int i = 2000; i <= 2030; i++) {
            if (i < 10) {
                jaarBox.addItem("0" + i);
            } else {
                jaarBox.addItem("" + i);
            }
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        toernooiAanmakenButton = new javax.swing.JButton();
        adresField = new javax.swing.JTextField();
        kostenField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        dagBox = new javax.swing.JComboBox();
        maandBox = new javax.swing.JComboBox();
        jaarBox = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        uurBox = new javax.swing.JComboBox();
        minuutBox = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Toernooi Aanmaken");

        toernooiAanmakenButton.setText("Maak toernooi aan");
        toernooiAanmakenButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                toernooiAanmakenButtonActionPerformed(evt);
            }
        });

        adresField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adresFieldActionPerformed(evt);
            }
        });

        jLabel1.setText("Datum(dd/mm/yyyy)");

        jLabel2.setText("Locatie");

        jLabel5.setText("Kosten");

        jLabel3.setText("Tijd");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(158, 158, 158)
                        .addComponent(toernooiAanmakenButton, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(41, 41, 41)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(kostenField, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
                                .addComponent(adresField, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(dagBox, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(20, 20, 20)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(uurBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(maandBox, 0, 60, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(minuutBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jaarBox, 0, 72, Short.MAX_VALUE))
                                .addGap(43, 43, 43)))))
                .addGap(41, 41, 41))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(dagBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jaarBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(maandBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(minuutBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(uurBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(adresField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(kostenField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(49, 49, 49)
                .addComponent(toernooiAanmakenButton)
                .addContainerGap(45, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void toernooiAanmakenButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_toernooiAanmakenButtonActionPerformed
// TODO add your handling code here:
    Toernooi aanmaken = new Toernooi();
    if(!kostenField.getText().equals("")) {
        if(!adresField.getText().equals("")) {
            String datumTijd = (String) jaarBox.getSelectedItem() + "-"
                    + (String) maandBox.getSelectedItem() + "-"
                    + (String) dagBox.getSelectedItem() + "-"
                    + (String) uurBox.getSelectedItem() + ":"
                    + (String) minuutBox.getSelectedItem()+":00";
            aanmaken.setDatumTijd(datumTijd);

            aanmaken.setLocatie(adresField.getText());
            aanmaken.setKosten(Double.parseDouble(kostenField.getText()));
            int Confirmer = JOptionPane.showConfirmDialog(null, "Zijn de gegevens correct?");
            if (Confirmer == JOptionPane.YES_OPTION) {
                if (aanmaken.insert() == true) {
                    JOptionPane.showMessageDialog(null, "Het toernooi is succesvol toegevoegd.");
                    System.out.println("Hier komen de ingevulde gegevens");
                    System.out.println(datumTijd);
                    System.out.println(adresField.getText());
                    System.out.println(aanmaken.getKosten());
                } else {
                    JOptionPane.showMessageDialog(null, "Er is een fout opgetreden");
                }
            } else {
                JOptionPane.showMessageDialog(null, "Het toernooi is niet aangemaakt");
            }
        }
        else {
            JOptionPane.showMessageDialog(null, "voer de lokatie in van het toernooi");
        }
}//GEN-LAST:event_toernooiAanmakenButtonActionPerformed
    else {
        JOptionPane.showMessageDialog(null, "voer de kosten in van het toernooi.");
    }
}

private void adresFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adresFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_adresFieldActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ToernooiAanmaken.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ToernooiAanmaken.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ToernooiAanmaken.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ToernooiAanmaken.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ToernooiAanmaken().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField adresField;
    private javax.swing.JComboBox dagBox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JComboBox jaarBox;
    private javax.swing.JTextField kostenField;
    private javax.swing.JComboBox maandBox;
    private javax.swing.JComboBox minuutBox;
    private javax.swing.JButton toernooiAanmakenButton;
    private javax.swing.JComboBox uurBox;
    // End of variables declaration//GEN-END:variables
}
